package com.ruoyi.web.controller.common;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;
import cn.hutool.captcha.generator.MathGenerator;
import cn.hutool.extra.servlet.ServletUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.sign.Base64;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;


/**
 * @author jianxin.wei
 * @description hutool的图形验证码类
 * @date 2024/10/18 15:55
 */
@RestController
public class MyCaptchaController {
    @GetMapping("myCaptchaImage")
    public AjaxResult getCode() {
        AjaxResult ajaxResult = AjaxResult.success();
        ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(100, 45, 2, 4);
        captcha.setGenerator(new MathGenerator(1)); // 参数为验证码四则运算中的数字长度
        captcha.createCode();
        MathGenerator mathGenerator = new MathGenerator();
        ajaxResult.put("img",captcha.getImageBase64());
        return ajaxResult;
    }
}
